package team.knowers.qzhserver.course.course.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import team.knowers.qzhserver.common.service.RedisService;
import team.knowers.qzhserver.course.course.entity.dao.CourseDO;
import team.knowers.qzhserver.course.course.service.CourseCacheService;

/**
 * 课程缓存管理Service实现类
 *
 * @author zcb
 * @date 2024/3/7 14:50
 */
@Service

public class CourseCacheServiceImpl implements CourseCacheService {
    @Autowired
    private RedisService redisService;
    @Value("${redis.expire.common}")
    private Long REDIS_EXPIRE;
    @Value("${redis.key.course}")
    private String REDIS_KEY_COURSE;

    @Override
    public void setCourse(CourseDO courseDO) {
        String key = REDIS_KEY_COURSE + ":" + courseDO.getId();
        redisService.set(key,courseDO,REDIS_EXPIRE);
    }

    @Override
    public CourseDO getCourse(String id) {
        String key = REDIS_KEY_COURSE + ":" + id;
        return (CourseDO) redisService.get(key);
    }

    @Override
    public void delCourse(String id) {
        String key = REDIS_KEY_COURSE + ":" + id;
        redisService.del(key);
    }
}
